




/*
William D. Hicks, Seth C. McKee, and Daniel A. Smith
   "Contemporary Views of Liberal Democracy and the 2016 Presidential Election" in PS
*/

/*
.DO file created by William D. Hicks (hickswd@appstate.edu)

It reproduces TABLES 1 and FIGURE 5 in the main manuscript. It also reproduces
TABLE B1 and FIGURES C1-C2 in SUPPLEMENTARY MATERIALS.  
 
Last update to this file: 5/6/2020 
This file directs the following tasks:
   (1) recodes and labels McCLosky's items
   (2) reproduce factor analysis reported in supplementary materials
   (3) reporoduces TABLE B1  
   (4) reporoduces scales from factor analysis that we use in models 
   (5) recodes control variables for use in models
   (6) reproduces models presented in TABLE 1 (and one additional model)
   (7) reproduces TABLE 1 in a .XLS file
       - TABLE_1.xls
   (8) reproduces extra TABLE in a .XLS file
       - TABLE_MODELS_EXTRA.xls
   (9) reproduces FIGURES 5 as .PDF, .EPS, and .TIF files
       - FIGURE_5.pdf, FIGURE_5.eps, FIGURE_5.tif
   (10) reproduces FIGURE C1 & C2 as .PDF, .EPS, and .TIF files
       - FIGURE_C1.pdf, FIGURE_C1.eps, FIGURE_C1.tif
	   - FIGURE_C2.pdf, FIGURE_C2.eps, FIGURE_C2.tif
*/

/*
                 YOU NEED TO FIRST IMPORT THE .DTA DATASET
                 THIS REQUIRES THAT YOU WRITE YOUR OWN PATH
*/

use ~[FILE PATH]/CCES16_HMS_REPLICATION.dta, clear 

/*
            OUTPUT (ALL TABLES & GRAPHS) SAVED TO ~DIRECTORY
    -you also need to set the appropriate location for a directory file - 
*/

cd [MAKE YOUR DIRECTORY HERE]



/* McClosky's Items on the 2016 CCES, MODIFIED FOR LATER USE */


foreach var of varlist HMS313A - HMS313I ///
{
		gen `var'_rev= (`var'*-1)+2
}

foreach var of varlist HMS313A_rev - HMS313I_rev ///
{
		recode `var' (-6=.)
}


lab var HMS313A_rev "...people should take law into their own hands"
label var HMS313B_rev "...innocent people suffer [improving the world]"
label var HMS313C_rev "Politician's methods don't matter..."
label var HMS313D_rev "...purpose justifies unfairness or brutality" 
label var HMS313E_rev "Politicians need to cut corners"
label var HMS313F_rev "Everyone should be able to vote"
label var HMS313G_rev "...mankind often requires cruelty & ruthlessness" 
label var HMS313H_rev "It's alright to get around the law..." 
label var HMS313I_rev "...use force to save true American way of life"


foreach var of varlist HMS406A - HMS406G ///
{
		gen `var'_rev= (`var'*-1)+2
}

foreach var of varlist HMS406A_rev - HMS406G_rev ///
{
		recode `var'(-6=.)
}
sum HMS406A_rev-HMS406G_rev	

lab var HMS406A_rev "Shouldn't teach foreign ideas in school" 
lab var HMS406B_rev "Censor books that contain wrong political views..." 
lab var HMS406C_rev "...may have to force people to testify against themselves..." 
lab var HMS406D_rev "...person has the right to face & question accusers"
lab var HMS406E_rev "Set free persons convicted by illegal evidence" 
lab var HMS406F_rev "Don't consider people who hide behind the law" 
lab var HMS406G_rev "...can't afford to depend on slow courts & laws" 


foreach var of varlist HMS403A - HMS403E ///
{
		gen `var'_rev= (`var'*-1)+2
}

foreach var of varlist HMS403A_rev - HMS403E_rev ///
{
		recode `var'(-6=.)
}

sum HMS403A_rev - HMS403E_rev	


lab var HMS403A_rev "...people don't know what's best for them" 
lab var HMS403B_rev "Few people know what's in their best interest..." 
lab var HMS403C_rev "Issues are beyond the understanding of most voters" 
lab var HMS403D_rev "...people lack sense to pick leaders wisely" 
lab var HMS403E_rev "...necessary to have few strong, able people in power" 


foreach var of varlist HMS411A - HMS411E ///
{
		gen `var'_rev= (`var'*-1)+2
}

foreach var of varlist HMS411A_rev - HMS411E_rev ///
{
		recode `var'(-6=.)
}

sum HMS411A_rev - HMS411E_rev

lab var HMS411A_rev "Some people are better, despite what we teach"
lab var HMS411B_rev "Some breeds of people are better than others" 
lab var HMS411C_rev "Certain races won't mix with Americans"
lab var HMS411D_rev "All races are certainly not equal" 
lab var HMS411E_rev "Minorities take over neightborhood if allowed..." 



/*         
        FACTOR ANALYSIS - FINDINGS ARE PRESENTED IN SUPPLEMENTARY MATERIALS 
*/

factor HMS313A_rev-HMS313I_rev HMS406A_rev-HMS406G_rev HMS403A_rev-HMS403E_rev HMS411A_rev-HMS411E_rev
/*
                          TABLE B1 in SUPPLEMENTARY MATERIALS
*/
rotate, promax blanks(.3)
estat common 


/*                      
                          MAKING SCALES FOR USE IN MODELS 
*/
* FACTOR 1, RACISM/XENOPHOBIA 
alpha HMS406A_rev HMS411B_rev HMS411C_rev HMS411D_rev HMS411E_rev, item gen(racism)

* FACTOR 2, AUTHORITARIANISM 
alpha HMS313A_rev HMS313B_rev HMS313D_rev HMS313G_rev HMS313I_rev, item gen(authoritarianism)

/* FACTOR 3, ELITISM */
alpha HMS403A_rev-HMS403D_rev, item gen(elitism)

corr racism authoritarianism elitism




/*                           
                              CONTROL VARIABLES 
See Ansolabehere, Stephen and Brian F. Schaffner. 2017. "CCES COMMON CONTENT, 2016,"
https://doi.org/10.7910/DVN/GDF6Z0, Harvard Dataverse, V4 for further information 
regarding variables provided in the survey's common content. This includes 
ALL variables that do not begin with the prefix HMS.
 
*/

* Policy Position Scale - each coded in a conservative direction
*gun control 
recode CC16_330d (1=0) (2=1) (3/9=.)

*immigration
recode CC16_331_1 (1=0) (2=1) (3/9=.) 

*abortion
recode CC16_332d  (1=1) (2=0) (3/9=.)

*environment 
recode CC16_333a (1=0) (2=1) (3/9=.)

*crime
recode CC16_334c (1=1) (2=0) (3/9=.)

egen PolicyPosition_base = rowtotal(CC16_330d CC16_331_1 ///
                                 CC16_332d CC16_333a CC16_334c), missing
sum PolicyPosition_base, meanonly								 
gen  PolicyPosition =  (PolicyPosition_base-r(min))/(r(max) - r(min))

label var PolicyPosition "Policy Position scale (conservative)" 

* Symbolic Ideology 

gen ideo3 = . 
replace ideo3 = 0 if  CC16_340a >=1 &  CC16_340a <=3
replace ideo3 = 1 if  CC16_340a == 4
replace ideo3 = 2 if  CC16_340a >= 5 &  CC16_340a <=7

label define ideo3 0 "Liberal" 1 "Moderate" 2 "Conservative" 
label val ideo3 ideo3

* Party Affiliation
gen pid3_nolean = . 
replace pid3_nolean = 0 if pid7 <=2
replace pid3_nolean = 1 if pid7>=3 & pid7<=5
replace pid3_nolean = 2 if pid7>=6 & pid7<=7

label define pid3_nolean 0 "Democrat" 1 "Independent/Leaner" 2 "Republican" 
label val pid3_nolean pid3_nolean


gen pid3_lean = . 
replace pid3_lean = 0 if pid7 <=3
replace pid3_lean = 1 if pid7==4
replace pid3_lean = 2 if pid7>=5 & pid7<=7

label define pid3_lean 0 "Democrat" 1 "Independent" 2 "Republican" 
label val pid3_lean pid3_lean


* Gender
gen female = . 
replace female = 1 if gender == 2
replace female = 0 if gender == 1

* Economy National 
recode CC16_302  (6/9=.) 
gen EconomyNational = 5-CC16_302
label var EconomyNational "Assessment of National Economy"  

*Economy Personal
recode CC16_303 (8/9=.)
gen EconomyPersonal = 5-CC16_303
label var EconomyPersonal "Assessment of Household Economy"  

*Race

gen race_w = . 
gen race_b = . 
gen race_h = . 
gen race_o = . 

replace race_w = 1 if race==1
replace race_w = 0 if race > 1
replace race_b = 1 if race==2
replace race_b = 0 if race==1 | race>2
replace race_h = 1 if race == 3
replace race_h = 0 if race<3 | race>3
replace race_o = 1 if race>3
replace race_o = 0 if race<=3 

*Education
recode educ (8/9=.)
gen Education = educ - 1
label var Education "Educational Attainment" 

* Political Sophistication : (1) Reps more conservative than Dems? 
*                            (2) Which party controls House (Reps)? 
*  						     (3) Which party controls Senate (Reps)?


recode CC16_340g (8=.a) (98=.b)
recode CC16_340h (8=.a) (98=.b)

gen knowledge1 = . 
replace knowledge1 = 1 if CC16_340g<CC16_340h 
replace knowledge1 = 0 if CC16_340g>CC16_340h
replace knowledge1 = 0 if CC16_340g==.a | CC16_340h==.a

gen knowledge2 = . 
replace knowledge2 = 1 if CC16_321a == 1
replace knowledge2 = 0 if CC16_321a > 1

gen knowledge3 = . 
replace knowledge3 = 1 if CC16_321b == 1
replace knowledge3 = 0 if CC16_321b > 1 & CC16_321b<8

gen knowledge_index = (knowledge1 + knowledge2 + knowledge3)/3 
label var knowledge_index "Political Sophistication scale" 


*vote, vote preference, thermometer difference

gen vote = . 
replace vote = 0 if CC16_410a == 6 | CC16_410a == 99
replace vote = 1 if CC16_410a== 2 
replace vote = 2 if CC16_410a== 1 

label define vote 0 "Abstain" 1 "Clinton" 2 "Trump" 
label val vote vote

gen vote_pref = .
 
replace vote_pref = 0 if CC16_410a>2 & CC16_410a<98
replace vote_pref = 1 if CC16_410a==2
replace vote_pref = 2 if CC16_410a==1

label define vote_pref 0 "Other" 1 "Clinton" 2 "Trump" 
label val vote_pref vote_pref

gen vote_pref_clinton = . 
replace vote_pref_clinton = 0 if vote_pref == 0 | vote_pref==2
replace vote_pref_clinton = 1 if vote_pref==1

gen vote_pref_trump = . 
replace vote_pref_trump = 0 if vote_pref== 0 | vote_pref == 1
replace vote_pref_trump = 1 if vote_pref ==2


recode HMS311a (997/998=.)
recode HMS311b (997/998=.)

gen THERM_DIFF = HMS311b-HMS311a



/* OUTCOME VOTE PREFERENCE */


mlogit vote_pref racism elitism authoritarianism ///
      i.pid3_lean i.ideo3 PolicyPosition female c.EconomyNational c.EconomyPersonal ///
	  i.race_b i.race_h i.race_o c.Education [pweight = weight], base(1)
estimates store VOTE_PREF

mlogit vote_pref_trump racism elitism authoritarianism ///
      i.pid3_lean i.ideo3 PolicyPosition female c.EconomyNational c.EconomyPersonal ///
	  i.race_b i.race_h i.race_o c.Education [pweight = weight]
estimates store VOTE_PREF_TRUMP

mlogit vote racism elitism authoritarianism  ///
      i.pid3_lean i.ideo3 PolicyPosition female c.EconomyNational c.EconomyPersonal ///
	  i.race_b i.race_h i.race_o c.Education knowledge_index [pweight = weight], base(1)
estimates store VOTE_ACT


reg THERM_DIFF racism elitism authoritarianism  ///
      i.pid3_lean i.ideo3 PolicyPosition female c.EconomyNational c.EconomyPersonal ///
	  i.race_b i.race_h i.race_o c.Education [pweight = weight]
estimates store THERM_DIFF

/*                             
                                 TABLE 1 IN MANUSCRIPT
*/


esttab THERM_DIFF VOTE_PREF VOTE_ACT using TABLE_1.xls, noomitted nobaselevels ///
        label unstack replace star(+ 0.10 * 0.05) ///
		cells(b(star fmt(3)) se(par(`"="("' `")""') fmt(3))) ///
		stats(N aic bic r2) drop() ///
		varlabels( _cons Constant ///
		1.race_b Black 1.race_h Hispanic 1.race_o Other ///
		racism "Racial Supremacy" elitism "Elitism" ///
		authoritarianism "Authoritarianism") ///
		mlabels() ///
		collabels(none) eqlabels("", none)  ///
		note(Note: First model is a regression whose dependent variable ///
		represents respondents' thermometer rating of Trump minus ///
		their rating of Clinton. Second ///
		model is a multinomial logit whose dependent variable separates ///
		respondents into three categories: prefer other, prefer Clinton, ///
		prefer Trump. Reference is preference for Clinton, preference other ///
		is suppressed. The third model ///
		is also multinomial logit whose dependent variable represents voting behavior ///
		in 2016: abstain, vote Clinton, vote Trump. Reference group is vote for Clinton, ///
		abstain is suppressed.) 
		

* UNREPORTED COMPARISON OF VOTE PREFERENCE MODEL AND ONE THAT COMBINES 
* FOLKS WHO PREFER CLINTON WITH FOLKS WHO PREFER ANYONE BUT TRUMP
  
esttab VOTE_PREF VOTE_PREF_TRUMP using TABLE_MODELS_EXTRA.xls, noomitted nobaselevels ///
        label unstack replace star(+ 0.10 * 0.05) ///
		cells(b(star fmt(3)) se(par(`"="("' `")""') fmt(3))) ///
		stats(N aic bic r2) drop() ///
		varlabels( _cons Constant ///
		1.race_b Black 1.race_h Hispanic 1.race_o Other ///
		racism "Racial Supremacy" elitism "Elitism" ///
		authoritarianism "Authoritarianism") ///
		mlabels() ///
		collabels(none) eqlabels("", none)  ///
		note(Note: First ///
		model is a multinomial logit whose dependent variable separates ///
		respondents into three categories: prefer other, prefer Clinton, ///
		prefer Trump. Reference is preference for Clinton. Second model ///
		is a logit whose dependent variable represents Trump preference, 1, versus ///
		preference for Clinton or other candidate.)

		
/*

                                    FIGURE 5 in MANUSCRIPT
*/
		
estimates restore VOTE_PREF

quietly margins, at( ///
        racism=(0(.2)1) pid3_lean=(1) ideo3=(1) female=(1) ///
		race_b=(0) race_h=(0) race_o=(0)) predict(outcome(2))	  
marginsplot, recast(scatter) level(90) ///
	plot1opts(mcolor(black) msymbol(circle)) ///
    ci1opts(lcolor(gs9) lwidth(thin) lpattern(solid)) ///
	ytitle(Pr(Prefer Trump)) yscale(range(0 1)) ylabel(0(.2)1, labs(small)) ///
	yline(0.5, lwidth(thin) lpattern(dash)) ///	
	xtitle(Racial Supremacy Scale) title("") xlab(, labs(small)) ///
	legend(order() rows(1)) ///
	scheme(economist) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
	saving(race.gph, replace)
	
quietly margins, at( ///
        elitism=(0(.2)1) pid3_lean=(1) ideo3=(1) female=(1) ///
		race_b=(0) race_h=(0) race_o=(0)) predict(outcome(2))	  
marginsplot, recast(scatter) level(90) ///
	plot1opts(mcolor(black) msymbol(circle)) ///
    ci1opts(lcolor(gs9) lwidth(thin) lpattern(solid)) ///
	ytitle(Pr(Prefer Trump)) yscale(range(0 1)) ylabel(0(.2)1, labs(small)) ///
	yline(0.5, lwidth(thin) lpattern(dash)) ///	
	xtitle(Elitism Scale) title("") xlab(, labs(small)) ///
	legend(order() rows(1)) ///
	scheme(economist) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
	saving(elite.gph, replace)
	
gr combine race.gph elite.gph, rows(1) ycommon ///
    graphregion(fcolor(white) icolor(white) lcolor(white))

gr export FIGURE5.pdf, replace 
gr export FIGURE5.eps, replace 
gr export FIGURE5.tif, replace 


/*                                      
                           FIGURE C1 IN SUPPLEMENTARY MATERIALS
*/

quietly margins pid3_lean, at( ///
        racism=(0(.2)1) ideo3=(1) female=(1) ///
		race_b=(0) race_h=(0) race_o=(0)) predict(outcome(2)) 
marginsplot, recast(scatter) level(90) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs6) msymbol(none)) ///
	plot3opts(mcolor(gs3) msymbol(diamond)) ///
	ci1opts(lcolor(gs9) lwidth(thin) lpattern(solid)) ///
	ci2opts(lcolor(none) lwidth(vthin) lpattern(blank)) ///
	ci3opts(lcolor(gs3) lwidth(vthin) lpattern(solid)) ///
	ytitle(Pr(Prefer Trump)) yscale(range(0 1)) ylabel(0(.2)1, labs(small)) ///
	yline(0.5, lwidth(thin) lpattern(dash)) ///	
	xtitle(Racial Supremacy Scale) title("") xlab(, labs(small)) ///
	legend(order(4 "Democrats" 5 "" 6 "Republicans") rows(1) ///
	region(fcolor(white) icolor(white) lcolor(white))) ///
	scheme(economist) graphregion(fcolor(white) icolor(white) lcolor(white))
	
gr export FIGURE_C1.pdf, replace 
gr export FIGURE_C1.tif, replace 
gr export FIGURE_C1.eps, replace 


/*                                      
                           FIGURE C2 IN SUPPLEMENTARY MATERIALS
*/

quietly margins pid3_lean, at( ///
        elitism=(0(.2)1) ideo3=(1) female=(1) ///
		race_b=(0) race_h=(0) race_o=(0)) predict(outcome(1)) 
marginsplot, recast(scatter) level(90) ///
	plot1opts(mcolor(gs9) msymbol(square)) ///
	plot2opts(mcolor(gs6) msymbol(none)) ///
	plot3opts(mcolor(gs3) msymbol(diamond)) ///
	ci1opts(lcolor(gs9) lwidth(thin) lpattern(solid)) ///
	ci2opts(lcolor(none) lwidth(vthin) lpattern(blank )) ///
	ci3opts(lcolor(gs3) lwidth(vthin) lpattern(solid)) ///
	ytitle(Pr(Prefer Clinton)) yscale(range(0 1)) ylabel(0(.2)1, labs(small)) ///
	yline(0.5, lwidth(thin) lpattern(dash)) ///	
	xtitle(Elitism Scale) title("") xlab(, labs(small)) ///
	legend(order(4 "Democrats" 5 "" 6 "Republicans") rows(1) ///
	region(fcolor(white) icolor(white) lcolor(white))) ///
	scheme(economist) graphregion(fcolor(white) icolor(white) lcolor(white))
	
gr export FIGURE_C2.pdf, replace
gr export FIGURE_C2.eps, replace
gr export FIGURE_C2.tif, replace



